{% extends 'Base/form_creator.html.twig' %}

{% import 'Base/from.item.html.twig' as FI %}
{% block content %}
    {#{{ dump(show) }}#}
    <div class="pad10">
        <mu-form ref="form" :model="en" class="" label-position="{{ show.vars.attr.labelPosition }}" label-width="100">

            <div class="layui-row">
                <div class="layui-col-md12 tal c11">
                    <blockquote class="layui-elem-quote  flex-r flex-center">
                        <span class="fa fa-tag"></span>
                        <span class="flex1 padl5">{{ title }}</span>
                        <mu-button @click="submit()">提交保存</mu-button>
                    </blockquote>
                </div>
            </div>
            {% block intro %}{% endblock %}
            {% block main %}{% for item in show.children %}{{ FI.row(item.vars) }}{% endfor %}{% endblock %}
            <mu-form-item>
                <mu-button color="primary" @click="submit()">提交保存</mu-button>
            </mu-form-item>
        </mu-form>
    </div>
{% endblock %}

{% block myJs %}
    <script>
        var Page
        $(function () {
            var refer = "{{ refer }}";
            Page = createVM("#Page", {
                en:{{ show.vars.attr.en |raw }}
                ,selectChoices:{}
            }, {
                "init": function () {
                }
                , "submit": function () {
                    var _this = this

                    $("textarea.UEditor").each(function () {
                        var name = $(this).attr("name")
                        var val = $(this).val();
                        eval("Page.en." + name + "=val")
                    });


                    var form = createForm(_this.en);
                    form["refer"] = refer;
                    apiPost("{{ show.vars.attr.action }}?cat={{ cat }}", form, function (res) {
                        showToast(res.i);
                        if (res.s == 1) {
                            console.log(res.d);
                            if (isTrue(refer)) {
                                setTimeout(function () {
                                    // history.go(-1);
                                    goto(refer);
                                    history.go(-1);
                                },500)
                            }else {
                                goto(res.d);
                            }


                        }
                    })
                }
                , ArratDelIndex: function (name, index) {
                    var data = this.en[name]
                    data = arrayDelIndex(data, index)
                    this.en[name] = data
                }
            })
            initPage()
        })
    </script>
{% endblock %}
